package com.mentalhealthplatform.teacherV2.dto;

import com.mentalhealthplatform.appModels.Teacher;
import com.mentalhealthplatform.global.rbac.dto.normal.RoleDTO;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Date;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

@Getter
@Setter
@NoArgsConstructor
public class TeacherDTO extends UserDTO {
    private String department;
    private String college;
    private String address;
    private Date birthDate;
    private String name;
    private String number;
    private String gender;
    private String phone;

    // Full-args constructor
    public TeacherDTO(UUID id, String username, boolean status, String department, String college, String address,
                      Date birthDate, String name, String number, String gender, String phone, Set<RoleDTO> roles) {
        super(id, username, status, roles);
        this.department = department;
        this.college = college;
        this.address = address;
        this.birthDate = birthDate;
        this.name = name;
        this.number = number;
        this.gender = gender;
        this.phone = phone;
    }

    public static TeacherDTO convertToDTO(Teacher teacher) {
        Set<RoleDTO> roleDTOs = teacher.getRoles().stream()
                .map(RoleDTO::convertToDTO)
                .collect(Collectors.toSet());

        return new TeacherDTO(
                teacher.getId(),
                teacher.getUsername(),
                teacher.isStatus(),
                teacher.getDepartment(),
                teacher.getCollege(),
                teacher.getAddress(),
                teacher.getBirthDate(),
                teacher.getName(),
                teacher.getNumber(),
                teacher.getGender(),
                teacher.getPhone(),
                roleDTOs
        );
    }
}